package com.dgw.springbootrabbitmq.sender;

import com.dgw.springbootrabbitmq.config.RpcConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class RpcClient {

    @Autowired
    private RabbitTemplate template;

    int start = 0;

    //@Scheduled(fixedDelay = 1000, initialDelay = 500)
    public void send() {
        System.out.println(" [x] Requesting fib(" + start + ")");
        Integer response = (Integer) template.convertSendAndReceive
            (RpcConfig.RPC_EXCHANGE_NAME, "rpc", start++);
        System.out.println(" [.] Got '" + response + "'");
    }
}